//
//  ZBLoginLogoView.m
//  ZhiBo
//
//  Created by huangtie on 2017/11/5.
//  Copyright © 2017年 huangtie. All rights reserved.
//

#import "ZBLoginLogoView.h"

@interface ZBLoginLogoView()

@property (nonatomic , strong) UIImageView *logoImage;

@property (nonatomic , assign) CGSize oldSize;

@end

@implementation ZBLoginLogoView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.oldSize = frame.size;
        self.backgroundColor = [UIColor whiteColor];
        
        self.logoImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo"]];
        [self.logoImage sizeToFit];
        self.logoImage.center = CGPointMake(self.width / 2, 20 + (self.height - 20) / 2);
        [self addSubview:self.logoImage];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    if (self.height < self.oldSize.height)
    {
        CGFloat scale = self.height / self.oldSize.height;
        [UIView animateWithDuration:.3 animations:^{
            self.logoImage.transform = CGAffineTransformScale(CGAffineTransformIdentity, scale,scale);
            self.logoImage.center = CGPointMake(self.width / 2, 20 + (self.height - 20) / 2);
        }];
        
    }
    else
    {
        [UIView animateWithDuration:.3 animations:^{
            self.logoImage.transform = CGAffineTransformIdentity;
            self.logoImage.center = CGPointMake(self.width / 2, 20 + (self.height - 20) / 2);
        }];
    }
}

@end
